/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.controller.interfaces.AbstractController;
import br.com.ufrn.aipetro.ga.domain.entity.device.Protocol;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Lucas
 *
 */
public class ProtocolController extends AbstractController<Protocol> {
	
	DaoFactory daoFactory;
	
	public ProtocolController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new Protocol());
	}
	
	public void changeName(String name) {
		getModel().setName(name);
	}
	
	public void persistDelete(Protocol protocol) {
		daoFactory.beginTransaction();
		daoFactory.createProtocolDao().delete(protocol);
		daoFactory.commitTransaction();
	}
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createProtocolDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createProtocolDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public List<Protocol> persistSearchByExample(Protocol example) {
		daoFactory.beginTransaction();
		List<Protocol> protocolList = daoFactory.createProtocolDao().searchByExample(example);
		daoFactory.commitTransaction();
		return protocolList;
	}

}
